import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  {
    path: '/transfusion/blood-part',
    component: Layout,
    redirect: '/example/table',
    name: 'transfusion-blood-part',
    meta: { title: '血液成分制备', icon: 'blood' },
    children: [
      {
        path: 'label-check',
        name: 'transfusion-blood-part-label-check',
        component: () => import('@/views/transfusion/blood-part/label-check/index'),
        meta: { title: '外科楼血液标签核对' }
      },
      {
        path: 'irradiated-blood',
        name: 'transfusion-blood-part-irradiated-blood',
        component: () => import('@/views/transfusion/blood-part/irradiated-blood/index'),
        meta: { title: '辐照血液录入与统计' }
      }
    ]
  },

  {
    path: '/transfusion-blood-stock',
    component: Layout,
    redirect: '/example/table',
    name: 'transfusion-blood-stock',
    meta: { title: '血液库存管理', icon: 'stock' },
    children: [
      {
        path: 'outbound-register',
        name: 'transfusion-blood-stock-outbound-register',
        component: () => import('@/views/transfusion/blood-stock/outbound-register/index'),
        meta: { title: '非发血出库登记表' }
      },
      {
        path: 'floating-personnel',
        name: 'transfusion-blood-stock-floating-personnel',
        component: () => import('@/views/transfusion/blood-stock/floating-personnel/index'),
        meta: { title: '野战流动人员信息录入' }
      },
      {
        path: 'takeout',
        name: 'transfusion-blood-stock-takeout',
        component: () => import('@/views//transfusion/blood-stock/takeout/index'),
        meta: { title: '外卖血液管理' }
      }
    ]
  },

  {
    path: '/transfusion/lab-test/report',
    component: Layout,
    redirect: '/example/table',
    name: 'transfusion-lab-test-report',
    meta: { title: '检验报告管理', icon: 'lab-test' },
    children: [
      {
        path: 'index',
        name: 'transfusion-lab-test-report-index-index',
        component: () => import('@/views/transfusion/lab-test/report/index/index'),
        meta: { title: '检验结果录入/修改' }
      },
      {
        path: 'result',
        name: 'transfusion-lab-test-report-result',
        component: () => import('@/views/transfusion/lab-test/report/result/index'),
        meta: { title: '检验报告确认' }
      },
      {
        path: 'result-reset',
        name: 'transfusion-lab-test-report-result-reset',
        component: () => import('@/views//transfusion/lab-test/report/result-reset/index'),
        meta: { title: '确认结果修改' }
      }
    ]
  },

  {
    path: '/transfusion-search',
    component: Layout,
    redirect: '/example/table',
    name: 'transfusion-search',
    meta: { title: '信息查询', icon: 'search' },
    children: [
      {
        path: 'duty-statistics',
        name: 'transfusion-search-duty-statistics-index',
        component: () => import('@/views/transfusion/search/duty-statistics/index'),
        meta: { title: '值班统计' }
      },
      {
        path: 'operation-appointment',
        name: 'transfusion-search-operation-appointment-index',
        component: () => import('@/views/transfusion/search/operation-appointment/index'),
        meta: { title: '住院病人手术预约查询' }
      },
      {
        path: 'tube-number-order',
        name: 'transfusion-search-tube-number-order',
        component: () => import('@/views/transfusion/search/tube-number-order/index'),
        meta: { title: '配血试管号排序' }
      },
      {
        path: 'blood-invalid-statistics',
        name: 'transfusion-search-blood-invalid-statistics',
        component: () => import('@/views/transfusion/search/blood-invalid-statistics/index'),
        meta: { title: '作废血液统计' }
      },
      {
        path: 'blood-match-statistics',
        name: 'transfusion-search-blood-match-statistics',
        component: () => import('@/views/transfusion/search/blood-match-statistics/index'),
        meta: { title: '配血主要工作量统计' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
